package com.stadium.common;

import com.stadium.common.enums.ResultEnum;

import java.io.Serializable;

/**
 * @program: common
 * @description:
 * @author: firstSeven
 * @create: 2019/12/17
 */

public class BaseResponse<T> implements Serializable {
    private static final long serialVersionUID = -1697733640925663374L;

    private int code;
    private String msg;
    private T data;
    private Integer total;

    public BaseResponse() {
    }

    public BaseResponse(int code) {
        this.code = code;
    }

    public BaseResponse(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public BaseResponse(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public BaseResponse(int code, String msg, T data, Integer total) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.total = total;
    }

    public BaseResponse(int code, String msg, Integer total) {
        this.code = code;
        this.msg = msg;
        this.total = total;
    }

    public static BaseResponse ok(){
        return new BaseResponse(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg(),0);
    }
    public static BaseResponse ok(String msg){
        return new BaseResponse(ResultEnum.SUCCESS.getCode(),msg);
    }

    public static <T> BaseResponse<T> ok(T data){
        return new BaseResponse(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg(),data,1);
    }
    public static <T> BaseResponse<T> ok(T data,String msg){
        return new BaseResponse(ResultEnum.SUCCESS.getCode(),msg,data,1);
    }
    public static <T> BaseResponse<T> ok(T data,Integer total){
        return new BaseResponse(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg(),data,total);
    }

    public static <T> BaseResponse<T> ok(Integer total){
        return new BaseResponse(ResultEnum.SUCCESS.getCode(),ResultEnum.SUCCESS.getMsg(),total);
    }

    public static BaseResponse error(){
        return new BaseResponse(ResultEnum.UNKNOWN_ERROR.getCode(),ResultEnum.UNKNOWN_ERROR.getMsg());
    }
    public static <T> BaseResponse<T> error(T data){
        return new BaseResponse(ResultEnum.UNKNOWN_ERROR.getCode(),ResultEnum.UNKNOWN_ERROR.getMsg(),data,0);
    }
    public static BaseResponse error(String msg){
        return new BaseResponse(ResultEnum.getCodeByMsg(msg).getCode(),msg,0);
    }
    public static BaseResponse error(Integer code){
        return new BaseResponse(code, ResultEnum.getMsgByCode(code).getMsg(),0);
    }
    public static BaseResponse error(ResultEnum resultEnum){
        return new BaseResponse(resultEnum.getCode(), resultEnum.getMsg(),0);
    }
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }
}
